package com.ydd.controller.user;

import com.ydd.dto.ArticleLisDTO;
import com.ydd.dto.RegisterDTO;
import com.ydd.result.Result;
import com.ydd.service.BasicDataService;
import com.ydd.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/index")
@Slf4j
@Api(tags = "前台基本数据相关接口")
public class BasicDataController {
    @Autowired
    private BasicDataService basicDataService;

    /**
     * 热门置顶文章数据
     *
     * @param page limit
     * @return
     */

    @GetMapping("/new")
    @ApiModelProperty("热门置顶文章数据(首页)接口")
    public Result topNewArticle(String page, String limit) {

        log.info("热门置顶文章数据(首页)参数:{}{}", page, limit);
        TopNewArticleVO topNewArticle = basicDataService.topNewArticle(page, limit);
        return Result.success(topNewArticle);
    }

    /**
     * 文章列表数据
     *
     * @param articleLisDTO
     * @return
     */
    @GetMapping("/list")
    @ApiModelProperty("文章列表数据")
    public Result ArticleLis(ArticleLisDTO articleLisDTO) {
        Map articleLisVO = basicDataService.ArticleLis(articleLisDTO);
        return Result.success(articleLisVO);
    }


    /**
     * 首页和全局数据
     *
     * @param
     * @return
     */

    @GetMapping("/index")
    @ApiModelProperty("首页和全局数据接口")
    public Result globleConfig() {

        log.info("首页和全局数据参数:{}");
        FrontGlobleConfigVO frontGlobleConfigVO = basicDataService.globleConfig();
        return Result.success(frontGlobleConfigVO);
    }


    /**
     * 推荐文章
     *
     * @param
     * @return
     */

    @GetMapping("/recommend")
    @ApiModelProperty("推荐文章接口")
    public Result recommend() {

        log.info("推荐文章参数:{}");
        RecommendArticleVO recommend = basicDataService.recommend();
        return Result.success(recommend);
    }

    /**
     * 用户注册
     *
     * @param
     * @return
     */

    @PostMapping("/reg")
    @ApiModelProperty("用户注册接口")
    public Result register(@RequestBody RegisterDTO registerDTO) {

        log.info("用户注册:{}");
        RegisterVO registerVO = basicDataService.register(registerDTO);
        return Result.success(registerVO);
    }

    /**
     * 最新文章
     *
     * @return
     */
    @GetMapping("/hot")
    @ApiModelProperty("最新文章")
    public Result hot() {

        log.info("最新文章参数:{}");
        ArticlessVo gethot = basicDataService.hot();
        return Result.success(gethot);
    }

    /**
     * 文章详情数据
     *
     * @param id
     * @return
     */
    @GetMapping("/show")
    @ApiModelProperty("最新文章")
    public Result show(Integer id) {

        log.info("最新文章参数:{}");
        ArticleDetailsDataVo getshow = basicDataService.show(id);
        return Result.success(getshow);
    }
}